import { BasicColumn, FormSchema } from '/@/components/Table';
import { defaultRule, rules } from '@/utils/common/validator';
import { userRemarkFormItem, userStatusFormItem, userStatusFormItemSelect } from '@/settings/ShareFormItem';
import { apiPostBrandCheckCodeUniqueQuery } from '@/api/http/system/auxiliary/brand/brand.api';
import { userRemarksColumn, userStatusColumn } from '@/settings/ShareTableColumns';

export const useBrandUpdateSchemaForm = (): FormSchema[] => {
  return [
    { field: 'name', label: '品牌名称', component: 'Input', rules: defaultRule() },
    {
      field: 'code',
      label: '编码',
      component: 'Input',
      dynamicRules: ({ model, schema }) => rules.uniqueFieldValidation(apiPostBrandCheckCodeUniqueQuery, 'id', schema, model),
    },
    {
      field: 'fileId',
      label: '附件',
      component: 'ImageUpload',
      componentProps: ({ formModel }) => {
        console.log();
        return {
          showUrl: formModel['showUrl'],
        };
      },
    },
    userStatusFormItem(),
    userRemarkFormItem(),
    { field: 'id', label: '品牌ID', component: 'Input', show: false },
    { field: 'showUrl', label: '附件', component: 'Input', show: false },
  ];
};

export const useBrandListColumns = (): BasicColumn[] => {
  return [{ title: '品牌名称', dataIndex: 'name' }, { title: '编码', dataIndex: 'code' }, userStatusColumn(), userRemarksColumn()];
};

export const useBrandListSearchForm = (): FormSchema[] => {
  return [{ field: 'name', label: '品牌名称', component: 'Input' }, { field: 'code', label: '品牌编码', component: 'Input' }, userStatusFormItemSelect()];
};
